package cn.udrm.water.base.v1.manager.entities;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedAttributeNode;
import javax.persistence.NamedEntityGraph;
import javax.persistence.NamedEntityGraphs;
import javax.persistence.Table;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import org.hibernate.annotations.GenericGenerator;

/**
 * 系统人员
 * @author liukang
 * @date 2019年3月22日
 */
@Getter
@Setter
@NoArgsConstructor
@Entity(name="BasePerson")
@Table(name="BASE_ORG_PERSON")
@NamedEntityGraphs({
	@NamedEntityGraph(name="BasePerson.department",
			attributeNodes={
			@NamedAttributeNode("department")
	}),
	@NamedEntityGraph(name="BasePerson.roles",
		attributeNodes={
		@NamedAttributeNode("roles")
	}),
	@NamedEntityGraph(name="BasePerson.departmentAndRoles",
	attributeNodes={
			@NamedAttributeNode("roles"),
			@NamedAttributeNode("department")
	})
})
public class BasePerson implements Serializable {
	
	private static final long serialVersionUID = 1L;
	@Id
	@GenericGenerator(name="idGenerator", strategy="uuid")
	@GeneratedValue(generator="idGenerator")
	@Column(name="ID")
	private String id;
	/*
	 * 人员名称
	 */
	private String name;
	private String enName;
	
	/*
	 * 人员所属部门
	 */
	@JoinColumn(name="DEPARTMENT_GUID")
	@ManyToOne(optional=true)
	private BaseDepartment department;
	/*
	 * 人员所属角色
	 */
	@ManyToMany
    @JoinTable(name="BASE_ORG_PERSON_ROLE", joinColumns=@JoinColumn(name="PERSON_GUID"),
    			inverseJoinColumns=@JoinColumn(name="ROLE_GUID"))
	private List<BaseRole> roles;

}
